package controllers;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JPanel;

import models.Minimap;
import models.tent.Tent;
import views.Screen;
import views.menu.tents.TentsMenu;

@SuppressWarnings("serial")
public class GamePanel extends JPanel {
	
	public Game game;
	public TentsMenu tentsMenu;
	public Minimap minimap;
	public Timer resourcesMenu;
	private InputHandler inputHandler;
	private MouseHandler mouseHandler;
	private Screen frame;
	public boolean tentPicked = false;
	public Tent tent;
	
	public GamePanel(int nRows, int nCols, int nTroops, Screen frame){
		game = new Game(nRows, nCols, nTroops);
		minimap = game.minimap;
		resourcesMenu = game.timer;
		this.frame = frame;
		
		inputHandler = new InputHandler(game);
		mouseHandler = new MouseHandler(this);
		
		tentsMenu = new TentsMenu(this);
		
		this.setFocusable(true);
		this.requestFocusInWindow();
		this.addKeyListener(inputHandler);
		
		
		this.addMouseListener(mouseHandler);

	}
	
	public void main(){
		this.setLayout(new GridBagLayout());
		
		GridBagConstraints constraints = new GridBagConstraints();
		
		//game stage settings
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.gridwidth = 2;
		constraints.gridheight = 1;
		constraints.weightx = 8.0;
		constraints.weighty = 0.3;
		constraints.fill = GridBagConstraints.BOTH;
		
		this.add(resourcesMenu, constraints);
		
		//game stage settings
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.gridwidth = 2;
		constraints.gridheight = 1;
		constraints.weightx = 8.0;
		constraints.weighty = 7.8;
		constraints.fill = GridBagConstraints.BOTH;
		
		this.add(game, constraints);
		
		//buttonsTents
		constraints.gridx = 0;
		constraints.gridy = 2;
		constraints.gridwidth = 1;
		constraints.gridheight = 1;
		constraints.weightx = 4.0;
		constraints.weighty = 0.5;
		constraints.fill = GridBagConstraints.NONE;
		
		this.add(tentsMenu, constraints);
		
		tentsMenu.gp = this;
		
		
		//minimap
		constraints.gridx = 1;
		constraints.gridy = 2;
		constraints.gridwidth = 1;
		constraints.gridheight = 1;
		constraints.weightx = 8.0;
		constraints.weighty = 0.5;
		constraints.fill = GridBagConstraints.BOTH;
		
		this.add(minimap, constraints);
		
		
		frame.addAsPanel(this);
		
		game.main();
	}
	
}
